package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    void insert(Orders order);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 根据订单状态查询订单
     * @param status
     * @return
     */
    Page<Orders> selectQueryPage(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据订单id查询订单信息
     * @param orderId
     * @return
     */
    @Select("select * from orders where id = #{orderId}")
    Orders selectByOrderId(Long orderId);

    /**
     * 统计待接单 待派送 派送中订单个数
     * @param status
     * @return
     */
    @Select("select count(*) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 根据订单状态和订单时间查询订单
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> selectByStatusAndOrderTime(Integer status, LocalDateTime orderTime);

    /**
     * 营业额数据统计
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    /**
     * 订单统计
     * @param map
     * @return
     */
    Integer countByMap(Map map);

    /**
     * 销量top10
     * @param map
     * @return
     */
    List<GoodsSalesDTO> getSalesTop10ByMap(Map map);
}
